<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="common/common_head :: commonHeader('物料信息录入')"/>
    <link th:href="@{/static/css/plugins/cropper/cropper.min.css}" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <form class="form-horizontal" method="post" id="materialForm">
        <div class="row">
            <div class="form-group">
                <div class="col-sm-8" style="margin-left: 16px">
                    <input class="btn btn-primary" type="button" onclick="save()" value="保存">
                    <button class="btn btn-primary" type="button" onclick="Dialog.closeFrame(window.name)">取 消</button>
                </div>
            </div>
            <!-- 显示 隐藏测试 -->
            <ul id="myTab" class="nav nav-tabs">
                <li class="active">
                    <a href="#basicinformation" linkTab="basicinformation" isActive="true" data-toggle="tab"> 基础信息</a>
                </li>
            </ul>
            <!-- 基本信息 -->
            <div id="basicinformation">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="form-group">
                            <label class="col-xs-1 control-label"><span class="required-sign">*</span>物料代码：</label>
                            <div class="col-xs-3">
                                <input id="materialCode" name="materialCode" type="text" class="form-control required">
                            </div>
                            <label class="col-xs-1 control-label"><span class="required-sign">*</span>物料描述：</label>
                            <div class="col-xs-3">
                                <input id="materialDesc" name="materialDesc" type="text" class="form-control required">
                                <input type="hidden" name="createdBy" th:value="${username}">
                            </div>
                            <label class="col-xs-1 control-label">物料类型：</label>
                            <div class="col-xs-3">
                                <select class="form-control" id="materialType" name="materialType" sysDict="WULX"
                                        emptyFirst="false"></select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label"><span class="required-sign">*</span>开始生效日期：</label>
                            <div class="col-sm-3">
                                <input class="form-control required" id="effectiveDate" name="effectiveDate">
                            </div>
                            <label class="col-sm-1 control-label"><span class="required-sign">*</span>库存数量：</label>
                            <div class="col-sm-3">
                                <input class="form-control required" id="qunatity" name="qunatity" type="number">
                            </div>
                            <label class="col-sm-1 control-label"><span class="required-sign">*</span>安全库存数量：</label>
                            <div class="col-sm-3">
                                <input onchange="kucun()" class="form-control" id="safeCont" name="safeCont"
                                       type="number">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">库存地点：</label>
                            <div class="col-sm-3">
                                <select class="form-control" id="storageLocation" name="storageLocation" sysDict="KCDD"
                                        emptyFirst="false"></select>
                            </div>
                            <label class="col-sm-1 control-label">工厂：</label>
                            <div class="col-sm-3">
                                <select class="form-control" id="werks" name="werks" sysDict="GC"
                                        emptyFirst="false"></select>
                            </div>
                            <label class="col-sm-1 control-label">备注：</label>
                            <div class="col-sm-3">
                                <input class="form-control" name="remark" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">采购组：</label>
                            <div class="col-sm-3">
                                <select class="form-control" id="purchaseGroup" name="purchaseGroup" sysDict="CGZ"
                                        emptyFirst="false"></select>
                            </div>
                            <label class="col-sm-1 control-label">储位：</label>
                            <div class="col-sm-3">
                                <input class="form-control" id="storage" name="storage" type="text">
                            </div>
                            <label class="col-sm-1 control-label">单位：</label>
                            <div class="col-sm-3">
                                <select class="form-control" id="basicUnit" name="basicUnit" sysDict="JLDW"
                                        emptyFirst="false"></select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<!-- Chosen -->
<script th:src="@{/static/js/plugins/chosen/chosen.jquery.js}"></script>
<script type="text/javascript">
    // 初始化时间插件
    laydate.render({elem: '#effectiveDate'});
    //初始化所有字典数据
    initDictDataSel();

    //保存
    function save() {
        if ($("#materialForm").valid()) {
            Page.ajaxPOST(ctxPath + "/material/save", $('#materialForm').serialize(), function (res) {
                Dialog.msg("新增成功!", function () {
                    //成功提示物料号展示给前台数据
                    parent.refresh();
                    Dialog.closeFrame(window.name);
                });
            });
        }
    }

    /**
     * @Description: 控制安全库存数量和库存数量
     */
    function kucun() {
        var safeCont = $("#safeCont").val();
        var qunatity = $("#qunatity").val();
        if (safeCont > qunatity) {
            Dialog.errorMsg("安全库存数量不可以大于库存数量!");
            $("#safeCont").val("");
        }
    }
</script>

</body>
</html>
